﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomerCareAuto.aspx.cs" Inherits="famails.BackEnd.Customer.CustomerCareAuto" MasterPageFile="~/Master.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <style type="text/css">
        .heartbeat {
            display: none;
            margin: 5px;
            color: blue;
        }
    </style>

    <script type="text/javascript">
        function templateChange() {
            var contentId = $('select#<%=drlContent.ClientID%> option:selected').val();
            var Content = document.getElementById("ContentPlaceHolder1_drlContent");
            var subject = Content.options[Content.selectedIndex].text;
            document.getElementById("ContentPlaceHolder1_txtSubject").value = subject;
            $.ajax({
                type: "POST",
                url: "send-register.aspx/getContentTemplate",
                data: '{contentId: "' + contentId + '" }',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: templateChangeSuccess,
                failure: function (response) {
                    alert("Không tồn tại mẫu này !");
                }
            });
        }

        function templateChangeSuccess(response) {
            if (response.d != null) {
                CKEDITOR.instances.ContentPlaceHolder1_txtBody.setData(response.d);
                var contentId = $('select#<%=drlContent.ClientID%> option:selected').val();
                var hiddenContentID = document.getElementById("ContentPlaceHolder1_hdfContentID");
                hiddenContentID.value = contentId;
            }
        }
        function signatureChange() {
            var SignId = $('select#<%=drlSign.ClientID%> option:selected').val();
            $.ajax({
                type: "POST",
                url: "send-register.aspx/getSign",
                data: '{SignId: "' + SignId + '" }',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: signatureChangeSuccess,
                failure: function (response) {
                    alert("Chữ ký không tồn tại!");
                }
            });
        }
        function signatureChangeSuccess(response) {
            var dataResponse = response.d;
            if (dataResponse != null) {
                var currentData = CKEDITOR.instances.ContentPlaceHolder1_txtBody.getData();
                var displayData = currentData + "</br>" + dataResponse;
                CKEDITOR.instances.ContentPlaceHolder1_txtBody.setData(displayData);
            }
        }
        function openNewWindow() {
            window.open("CreateContentMail.aspx?Id=0", "_blank",
            "toolbar=yes, scrollbars=yes, resizable=yes,top=100, left=100, width=1000, height=600");
        }
        function insertHello() {
            var firtHello = document.getElementById("ContentPlaceHolder1_txtWelcome");
            var lastHello = document.getElementById("ContentPlaceHolder1_txtAfterWelcome");
            var customerName = document.getElementById("ContentPlaceHolder1_rdoCustomerName");
            var Wellcome = firtHello.value + " " + "[khachhang]" + " " + lastHello.value;
            if (customerName.checked == true) {
                Wellcome;
            }
            else {
                Wellcome = firtHello.value + " " + "[email]" + " " + lastHello.value;
                alert(Wellcome);
            }
            var currentData = CKEDITOR.instances.ContentPlaceHolder1_txtBody.getData();
            var displayData = Wellcome + "</br>" + currentData;
            CKEDITOR.instances.ContentPlaceHolder1_txtBody.setData(displayData);
        }
    </script>
    <script>
        jQuery(function ($) {
            //loadProductGroup();
            //$('#jqxTree').trigger('select');
            //$("#jqxTree").jqxTree('val', $("#p_groupitem").val());
            //alert($("#p_groupitem").val());
            function loadProductGroup() {
                try {
                    ///alert('load');
                    $.ajax({
                        type: "POST",
                        url: "CustomerCareAuto.aspx/LoadTree",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            if (data.d != undefined) {
                                var html = "<ul>";
                                $.each(data.d, function (i, item) {
                                    if (item.children != undefined) {
                                        if (i == 0) html += "<li  item-selected='true' item-expanded='true' item-value='" + item.ProductGroupID + "'>" + item.ProductGroupName;
                                        else html += "<li item-expanded='true' item-value='" + item.ProductGroupID + "'>" + item.ProductGroupName;
                                        //alert(item.children.count);
                                        if (item.children != "") {
                                            html += "<ul>";
                                            html += getChild(item.children);
                                            html += "</ul>";
                                        }
                                        html += "</li>";
                                    }
                                });
                                html += "</ul>";
                            }
                            $("#jqxTree").append(html);
                            $("#dropDownButton").jqxDropDownButton({ width: $("#ContentPlaceHolder1_drlMailConfig").width, height: 20 });
                            $('#jqxTree').on('select', function (event) {
                                var args = event.args;
                                var item = $('#jqxTree').jqxTree('getItem', args.element);
                                $("#ContentPlaceHolder1_p_groupid").val(item.value);
                                $("#p_groupitem").val(item);
                                var dropDownContent = '<div style="position: relative; margin-left: 3px; margin-top: 5px;">' + item.label + '</div>';
                                $("#dropDownButton").jqxDropDownButton('setContent', dropDownContent);
                                //loadProduct();
                            });
                            $("#jqxTree").jqxTree({ height: 220, width: 500 });
                        }
                    });
                }
                catch (err) { alert(err.message); }
            }
            function getChild(child) {
                var html = "";
                if (child != "") {
                    $.each(child, function (i, item) {
                        html += "<li item-expanded='true' item-value='" + item.ProductGroupID + "'>" + item.ProductGroupName;
                        if (item.children != "") {
                            html += "<ul>";
                            html += getChild(item.children);
                            html += "</ul>";
                        }
                        html += "</li>";
                    });
                }
                return html;
            }
        });
    </script>
    <input type="hidden" id="p_groupitem" />
   <%-- <asp:ScriptManager runat="server"></asp:ScriptManager>
    <asp:UpdatePanel runat="server">
        <ContentTemplate>--%>
            <asp:HiddenField runat="server" ID="p_groupid" />
            <div style="width: 100%; padding: 10px;">

                <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="border: 1px solid #333; padding: 0px; margin-bottom: 10px;">
                    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="padding: 10px 20px; background: #000; color: #fff; font-size: 18px; font-weight: bold; position: relative;">
                        Thiết lập thời gian gửi
                    </div>
                    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 10px;">
                        <asp:Panel Visible="false" ID="pnError" runat="server">
                            <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12 error-box round">
                                <asp:Label ID="lblError" runat="server" Text=""></asp:Label>
                            </div>
                        </asp:Panel>
                        <asp:Panel Visible="false" ID="PanelHourError" runat="server">
                            <div class="error-box round">
                                <asp:Label ID="lblHourError" runat="server" Text=""></asp:Label>
                            </div>
                        </asp:Panel>

                        <asp:Panel Visible="false" ID="pnSuccess" runat="server">
                            <div class="col-md-12 col-xs-12 col-sm-12 confirmation-box round">
                                <asp:Label ID="lblSuccess" runat="server" Text=""></asp:Label>
                            </div>
                        </asp:Panel>
                        <asp:HiddenField ID="hdfCustomerCareAutoId" runat="server" />
                    </div>
                    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 10px;">
                        <fieldset>
                            <asp:HiddenField ID="HiddenField1" runat="server" />
                            <label for="simple-input" style="font-weight: bolder; text-transform: none">
                                Tiêu đề</label>
                            <asp:TextBox ID="txtAutoName" runat="server"
                                CssClass="form-control" Style="border: 1px solid #333; border-radius: 0px;" ToolTip="Nhập tựa đề bài viết"></asp:TextBox>
                        </fieldset>
                    </div>
                    <div class="col-md-6 col-xs-12 col-sm-12 col-lg-6" style="height: auto; padding: 10px;">
                        <fieldset>
                            <label for="simple-input" style="font-weight: bolder; text-transform: none">
                                Chọn email gửi</label>
                            <asp:DropDownList ID="drlMailConfig" CssClass="form-control" Style="margin-bottom: 5px; border: 1px solid #333; border-radius: 0px;" runat="server">
                            </asp:DropDownList>
                        </fieldset>
                    </div>
                    <div class="col-md-6 col-xs-12 col-sm-12 col-lg-6" style="height: auto; padding: 10px;">
                        <fieldset>
                            <label for="simple-input" style="font-weight: bolder; text-transform: none">
                                Chọn nhóm khách hàng gửi kèm</label>
                            <asp:DropDownList ID="ddlCustomerGroup" CssClass="form-control" Style="margin-bottom: 5px; border: 1px solid #333; border-radius: 0px;" runat="server">
                            </asp:DropDownList>
                        </fieldset>
                    </div>
                    <div class="col-md-6 col-xs-12 col-sm-12 col-lg-6" style="height: auto; padding: 10px;">
                        <fieldset>
                            <label for="simple-input" style="font-weight: bolder; text-transform: none">
                                Chọn nhóm sản phẩm gửi kèm</label>
                            <%--<div id="dropDownButton" class="form-control" style="background: #fff; color: #333; border: 1px solid #333; border-radius: 0px; height: 32px;">
                                <div id="jqxTree">
                                </div></div>--%>
                                <asp:DropDownList ID="ddlProductList" CssClass="form-control" Style="margin-bottom: 5px; border: 1px solid #333; border-radius: 0px;" runat="server">
                            </asp:DropDownList>
                            
                        </fieldset>
                    </div>
                    <div class="col-md-6 col-xs-12 col-sm-12 col-lg-6" style="height: auto; padding: 10px;">
                        <fieldset>
                            <label for="simple-input" style="font-weight: bolder; text-transform: none">
                                Trạng thái</label>
                            <asp:CheckBox runat="server" ID="cbIsStop" Text="Khóa" />
                        </fieldset>
                    </div>
                    <style>
                        #ContentPlaceHolder1_chkDefaultPage {
                            margin-right: 0px;
                            margin-top: 6px;
                        }
                    </style>

                    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: 10px; background: #333; padding: 0px; margin: 10px 0px;">
                    </div>

                    <div class="col-md-6 col-xs-12 col-sm-12 col-lg-6" style="height: auto; padding: 10px;">
                        <fieldset>
                            <label for="simple-input" style="font-weight: bolder; text-transform: none">
                                Chọn nội dung</label>
                            <asp:DropDownList ID="drlContent" CssClass="form-control" Style="border: 1px solid #333; border-radius: 0px;" runat="server"
                                AutoPostBack="false" onchange="templateChange()">
                            </asp:DropDownList>
                        </fieldset>
                    </div>
                    <div class="col-md-6 col-xs-12 col-sm-12 col-lg-6" style="height: auto; padding: 10px;">
                        <fieldset>
                            <label for="simple-input" style="font-weight: bolder; text-transform: none">
                                Chọn chữ ký</label>
                            <asp:DropDownList ID="drlSign" CssClass="form-control" Style="border: 1px solid #333; border-radius: 0px;" runat="server"
                                AutoPostBack="false" onchange="signatureChange()">
                            </asp:DropDownList>
                        </fieldset>
                    </div>
                    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 0px;">
                        <div class="col-md-2 col-xs-12 col-sm-4 col-lg-2" style="height: auto; padding: 10px;">
                            <fieldset>
                                <asp:TextBox ID="txtWelcome" CssClass="form-control" Style="margin-bottom: 5px; border: 1px solid #333; border-radius: 0px;" runat="server"
                                    ToolTip="Nhập lời chào cho bức thư!">Chào</asp:TextBox>
                            </fieldset>
                        </div>
                        <div class="col-md-2 col-xs-12 col-sm-4 col-lg-2" style="height: auto; padding: 16px;">
                            <fieldset>
                                <asp:RadioButton ID="rdoCustomerName" Checked="true" GroupName="groupWelcome" runat="server" />Tên
                            khách hàng
                            </fieldset>
                        </div>
                        <div class="col-md-2 col-xs-12 col-sm-4 col-lg-2" style="height: auto; padding: 16px;">
                            <fieldset>
                                <asp:RadioButton ID="rdoCustomerEmail" GroupName="groupWelcome" runat="server" />Email
                            khách hàng
                            </fieldset>
                        </div>
                        <div class="col-md-4 col-xs-10 col-sm-6 col-lg-4" style="height: auto; padding: 10px;">
                            <fieldset>
                                <asp:TextBox ID="txtAfterWelcome" CssClass="form-control" Style="margin-bottom: 5px; border: 1px solid #333; border-radius: 0px;"
                                    runat="server">thân mến !</asp:TextBox>
                            </fieldset>
                        </div>
                        <div class="col-md-2 col-xs-2 col-sm-6 col-lg-2" style="height: auto; padding: 10px 10px 0px 0px;">
                            <fieldset>
                                <asp:Button Style="background: #333; color: #fff; text-align: center; padding: 6px 11px; border-radius: 0px; width: 100%; min-width: 32px; min-height: 32px" OnClick="insertHello()" class="btn">
                                    <span class="fa fa-plus" style="float: left; font-size: 20px"></span><span class="hidden-xs">Thêm lời chào</span>
                                </asp:Button>
                            </fieldset>
                        </div>
                    </div>
                    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 10px;">
                        <fieldset>
                            <asp:HiddenField ID="hdfContentID" runat="server" />

                            <label for="simple-input" style="font-weight: bolder; text-transform: none">
                                Tiêu đề nội dung</label>
                            <asp:TextBox ID="txtSubject" runat="server"
                                CssClass="form-control" Style="border: 1px solid #333; border-radius: 0px;" ToolTip="Nhập tiêu đề bức thư của bạn"></asp:TextBox>
                        </fieldset>
                    </div>
                    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 10px;">
                        <fieldset>
                            <asp:TextBox ID="txtBody" class="ckeditor" Style="border: 1px solid #333; border-radius: 0px;" runat="server" TextMode="MultiLine" AutoPostBack="true"></asp:TextBox>
                        </fieldset>
                    </div>
                    <div class="col-md-4 col-xs-12 col-sm-6 col-lg-4" style="height: auto; padding: 10px;">
                        <fieldset>
                            <div style="float: left; background: #333; color: #fff; text-align: center; padding: 7px 15px; border-radius: 0px;">
                                <span class="fa fa-clock-o" style="margin-right: 10px;"></span>Cấu hình thời gian gửi ( tính theo giờ )
                            </div>
                        </fieldset>
                    </div>
                    <div class="col-md-4 col-xs-12 col-sm-6 col-lg-2" style="height: auto; padding: 10px;">
                        <fieldset>
                            <asp:TextBox ID="txtOrderNo" runat="server" placeholder="Thứ tự gửi" CssClass="form-control" Style="border: 1px solid #333; border-radius: 0px;"></asp:TextBox>
                        </fieldset>
                    </div>
                    <div class="col-md-4 col-xs-12 col-sm-6 col-lg-2" style="height: auto; padding: 10px;">
                        <fieldset>

                            <asp:TextBox ID="txtHour" placeholder="Thời gian gửi" runat="server" CssClass="form-control" Style="border: 1px solid #333; border-radius: 0px;"></asp:TextBox>
                        </fieldset>
                    </div>
                    <div class="col-md-4 col-xs-12 col-sm-12 col-lg-4" style="height: auto; padding: 10px;">
                        <fieldset>
                            <button id="adhjskd" runat="server" class="btn" style="float: left; margin-right: 10px; background: #333; color: #fff; text-align: center; padding: 6px 15px; border-radius: 0px;"
                                onserverclick="btnSaveContent_Click">
                                <i style="margin-right: 10px;" class="fa fa-save"></i>Thêm
                            </button>
                        </fieldset>
                    </div>
                    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="margin-top: 10px; padding: 10px 20px; background: #000; color: #fff; font-size: 18px; font-weight: bold; position: relative;">
                        Danh sách nội dung đã cấu hình
                    </div>
                    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 10px; margin-bottom: 30px;">
                        <fieldset>
                            <div class=" table-responsive">
                                <asp:Label ID="lbl" runat="server" Text=""></asp:Label>
                                <asp:HiddenField ID="hdfContentIdEdit" runat="server" />
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                            <th style="width: 80px; text-align: center">No.</th>
                                            <th>Tiêu đề</th>
                                            <th>Thời gian</th>
                                            <th style="width: 100px;">Tùy chỉnh</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <asp:Repeater ID="dlContentSendCustomerCareAuto" runat="server">
                                            <ItemTemplate>
                                                <tr>
                                                    <td style="text-align: center;">
                                                        <asp:Label ID="lblNo" runat="server" Text=""></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:Label Style="color: #333; text-decoration: none;" ID="lbtContent" runat="server"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:Label ID="lblHour" runat="server" Text=""></asp:Label>
                                                    </td>
                                                    <td style="text-align: center;">
                                                        <asp:LinkButton Style="color: #333;" ID="lbtEdit" runat="server" Visible='<%#Eval("id")+""==""?false:true %>'
                                                            OnClick="lbtEdit_Click1" CommandArgument='<%#Eval("id") %>'>
                                        <span style="font-size:20px;margin-right:10px;" class="fa fa-pencil"></span>
                                                        </asp:LinkButton>
                                                        <asp:LinkButton Style="color: #333;" ID="lbtContentDelete" runat="server"
                                                            OnClientClick="return confirmDelete('Nếu tiếp tục dữ liệu sẽ bị xóa khỏi hệ thống ?')"
                                                            OnClick="lbtContentDelete_Click">
                                        <span style="font-size:20px;" class="fa fa-trash-o"></span>
                                                        </asp:LinkButton>
                                                    </td>
                                                </tr>
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </tbody>
                                </table>
                            </div>
                        </fieldset>
                    </div>
                    <div class="col-md-12 col-xs-12 col-sm-12 col-lg-12" style="height: auto; padding: 10px;">
                        <button id="Button1" runat="server" class="btn col-md-2 col-xs-6 col-sm-3 col-lg-2" style="float: left; border: 1px solid #fff; background: #333; color: #fff; text-align: center; padding: 6px 15px; border-radius: 0px;"
                            onserverclick="btnSaveContentAndCustomerCareAuto_Click">
                            <i style="margin-right: 10px;" class="fa fa-save"></i>Lưu
                        </button>
                        <button id="Button2" runat="server" class="btn col-md-2 col-xs-6 col-sm-3 col-lg-2" style="float: left; border: 1px solid #fff; background: #333; color: #fff; text-align: center; padding: 6px 15px; border-radius: 0px;"
                            onserverclick="btnCreateNew_Click">
                            <i style="margin-right: 10px;" class="fa fa-refresh"></i>Tạo mới
                        </button>
                    </div>

                </div>
            </div>
<%--        </ContentTemplate>
    </asp:UpdatePanel>--%>
</asp:Content>

